package com.tongji.diy.view.component3D
{
	import com.tongji.diy.utils.ArcBorderUtils;
	import com.tongji.diy.view.component3D.ShapeToAdd;
	
	import flare.core.Mesh3D;
	
	import flash.geom.Point;
	import flash.geom.Vector3D;
	
	public class ShapeToAddArc extends ShapeToAdd
	{
		//points保存从start前一个点到end后一个点的数据
		private var _points:Vector.<Point> = new Vector.<Point>;
		
		private const N:uint = ArcBorderUtils.N;
		private const STEP:Number = ArcBorderUtils.STEP;
		
		public function ShapeToAddArc(roomShapePoints:Vector.<Point>,pos:Vector3D, roomBorder:RoomBorder, name:String = "")
		{
			//roomShapePoints存的3个控制点
			super(roomShapePoints,pos,roomBorder);
			
			/*
			画墙
			*/
			
			//ArcBorderUtils.bezier Curve
			var sP:Point = new Point(roomShapePoints[0].x,roomShapePoints[0].y);
			var cP:Point = new Point(roomShapePoints[1].x,roomShapePoints[1].y);
			var eP:Point = new Point(roomShapePoints[2].x,roomShapePoints[2].y);
			
			_points.push(new Point(roomBorder.start.data.x,roomBorder.start.data.y));
			for(var i:uint = 0;i <= uint(1/this.STEP);i++)
			{
				//point at i
				var p:Point = new Point();
				p.x = sP.x*ArcBorderUtils.bez(N,0,i*STEP)+cP.x*ArcBorderUtils.bez(N,1,i*STEP)+eP.x*ArcBorderUtils.bez(N,2,i*STEP);
				p.y = sP.y*ArcBorderUtils.bez(N,0,i*STEP)+cP.y*ArcBorderUtils.bez(N,1,i*STEP)+eP.y*ArcBorderUtils.bez(N,2,i*STEP);
				_points.push(p);
			}
			_points.push(new Point(roomBorder.end.data.x,roomBorder.end.data.y));
			
			for(var j:uint = 0; j < _points.length-3; j++)
			{
				borders.push(new Mesh3D());
				this.drawBorder(borders[j], _points[j], _points[j+1], _points[j+2],_points[j+3]);
			}
			
			/*
			调整位置
			*/
			
			this.refresh(pos,roomBorder);
		}
		
		override public function refresh(pos:Vector3D,roomBorder:RoomBorder):void
		{
			this._roomBorder = roomBorder;
			this.setPos(pos,roomBorder);
			this.setRot(roomBorder.getNormal());
		}
		
		public function get points():Vector.<Point>
		{
			return _points;
		}
	}
}